package com.googlecode.animeclassifier;

import java.io.File;
import java.util.Collection;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *  Bracket-based file which is filename like [AAA][BBB][CCC].avi
 */
@SuppressWarnings("serial")
public class BracketFile {
	/**
	 * FOR DEBUG ONLY
	 */
	private static final boolean DEBUG = false;
	private static final String BRACKET_PATTERN_STRING = "\\[[^\\[\\]]*\\]";
	Pattern BRACKET_PATTERN = Pattern.compile(BRACKET_PATTERN_STRING);
	private File file;
	
	/**
	 * Bracket strings which without bracket quote
	 */
	Collection<String> brackets;

	public BracketFile(File arg0, String arg1) {
		file = new File(arg0, arg1);
		parseFilename();
	}
	
	public BracketFile(String arg0) {
		file = new File(arg0);
		parseFilename();
	}
	
	/**
	 * Parse filename, split it into many bracket
	 */
	private void parseFilename() {
		String name = file.getName();
		brackets = new LinkedList<String>();
		
		Matcher m = BRACKET_PATTERN.matcher(name);
		
		if(DEBUG) System.out.println("Name: " + name);
		while(m.find()) {
				if(DEBUG) System.out.println(m.group());
				String one = m.group();
				brackets.add(one.substring(1, one.length() - 1));
		}
	}

	public String toString() {
		return file.toString();
	}

	/**
	 * @return the file
	 */
	public File getFile() {
		return file;
	}
}
